#pragma once
#include <QOpenGLWindow>
#include <QVector>


class QOpenGLFunctions_3_3_Core;
class QOpenGLBuffer;
class Camera;
class MeshProg;
class Model3D;

struct Light;
struct aiScene;
struct aiNode;
struct aiMesh;


class ModelViewer : public QOpenGLWindow
{
    Q_OBJECT

public:
    ModelViewer();
    virtual ~ModelViewer();

    QString contextInformation() const;
    void setModel(Model3D*);

protected:
    virtual void initializeGL();
    virtual void paintGL();
    virtual void resizeGL(int w, int h);
    virtual void keyPressEvent(QKeyEvent* ev);
    virtual void mouseMoveEvent(QMouseEvent *ev);
    virtual void wheelEvent(QWheelEvent *ev);

private slots:
    void reset();
    void reloadModel();

private:
    void processNode(const aiNode* node);
    MeshProg* processMesh(const aiMesh* mesh);
    void clearProg();

private:
    QOpenGLFunctions_3_3_Core*  glFunc_;

    Camera*                     camera_;
    bool                        firstMouse_;
    QPoint                      lastMousePos_;

    Model3D*                    model_;
    QVector<MeshProg*>          prog_;
};
